<?php

namespace App\Http\Controllers\Api\v1;

use App\common;
use App\Http\Controllers\Controller;
use App\Logic\realeEstateLogic;
use App\Models\RealEstates;
use Illuminate\Http\Request;
/**
 * 楼盘
 * @name zf
 */
class RealeEstatecontroller extends Controller{

    /**
     * Undocumented function
     *  楼盘列表
     * @return void
     */
    public function realeEstateList(Request $request){
        try{
            if($request->method()!= 'GET')throw new \Exception('请求方式不正确');
           $realeEstateList=realeEstateLogic::realeEstateList();
            return common::success(20000,$realeEstateList,'加载成功');
        }catch(\Exception  $e){
            return common::fail(2001,'',$e->getMessage());
        }
    }
    /**
     * Undocumented function
     *  楼盘详情
     * @return void
     */
    public function realeEstateDetail(Request $request){
        try{
            if($request->method()!= 'GET')throw new \Exception('请求方式不正确');
            $id=$request->get('id');
            $realeEstate=realeEstateLogic::realeEstateDetail($id);
            return common::success(20000,$realeEstate,'加载成功');
        }catch(\Exception  $e){
            return common::fail(2001,'',$e->getMessage());
        }
    }
    /**
     * Undocumented function
     *  楼盘信息存入es
     * @return void
     */
    public function realeEstateEsCreate(Request $request){
        try{
            if($request->method()!= 'GET')throw new \Exception('请求方式不正确');
            $realeEstateList=RealEstates::get()->toArray();
            $res=realeEstateLogic::realeEstateEsCreate($realeEstateList);
            return common::success(20000,$res,'加载成功');
        }catch(\Exception  $e){
            return common::fail(2001,'',$e->getMessage());
        }
    }
    /**
     * Undocumented function
     *  楼盘信息es搜索
     * @return void
     */
    public function realeEstateEsIdex(Request $request){
        try{
            if($request->method()!= 'GET')throw new \Exception('请求方式不正确');
            $name=$request->get('name');
            $realeEstateData=realeEstateLogic::realeEstateEsIndex($name);
            return common::success(20000,$realeEstateData,'加载成功');
        }catch(\Exception  $e){
            return common::fail(2001,'',$e->getMessage());
        }
    }
    /**
     * Undocumented function
     *  楼盘信息编辑
     * @return void
     */
    public function realeEstateSave(Request $request){
        try{
            if($request->method()!= 'POST')throw new \Exception('请求方式不正确');
            $realeEstateSave=$request->post();
            $status=realeEstateLogic::realeEstateSave($realeEstateSave,$request);
            return common::success(20000,$status,'加载成功');
        }catch(\Exception  $e){
            return common::fail(2001,'失败',$e->getMessage());
        }
    }
    /**
     * Undocumented function
     *  楼盘删除
     * @return void
     */
    public function realeEstateDel(Request $request){
        try{
            $id=$request->get('id');
            $realeEstateDetail=RealEstates::del('id',$id);
            return common::success(20000,$realeEstateDetail,'成功');
        }catch(\Exception  $e){
            return common::fail(2001,'失败',$e->getMessage());
        }
    }
    /**
     * Undocumented function
     *  楼盘存储redis
     * @return void
     */
    public function realeEstateRedis(Request $request){
        $realeEstateDetail=realeEstateLogic::realeEstateRedis();
        return common::success(20000,$realeEstateDetail,'成功');
    }
    /**
     * 楼盘排行榜添加
     */
    public function FloorRanking(Request $request){
        try{
            $PropertyName=$request->get('PropertyName');
            $RankingMethod=$request->get('RankingMethod');
            $floorRanking=realeEstateLogic::floorRanking($PropertyName,$RankingMethod);
            return common::success(20000,$floorRanking,'浏览数据成功');
        }catch(\Exception  $e){
            return common::fail(2001,'',$e->getMessage());
        }
    }
    public function floorLookDay(){
        try{
            $floorRanking=realeEstateLogic::day();
            return common::success(20000,$floorRanking,'日展示成功');
        }catch(\Exception  $e){
            return common::fail(2001,'',$e->getMessage());
        }
    }
    public function floorLookWeek(){
        try{
            $floorRanking=realeEstateLogic::week();
            return common::success(20000,$floorRanking,'周展示成功');
        }catch(\Exception  $e){
            return common::fail(2001,'',$e->getMessage());
        }
    }
}

